clear
use SatisfiedorDepressed12302024.dta

**Descriptive variables
estpost summarize lifesatisfaction cesd10/*
*/ workcare4_1-workcare4_4 workcare9_* /*
*/ female ruralh agegroup50_* cohort_* chrode5flag adlfive /*
*/ formalsector educl_* hhasset_quartile_* married nokidcont nosocialact /*
*/ if flagsample==1 & wave==1 & agegroup50<=2
esttab, cells("mean(fmt(3)) sd(fmt(3))")
est sto wave1pooled

**RE models, continuous
global A i.female 
global B i.ruralh  
global C i.chrode5flag c.adlfive i.agegroup50 ib1930.cohort i.lost
global D i.formalsector i.educl i.hhasset_quartile 
global E i.married i.nokidcont i.nosocialact


**lifesatisfaction
qui xtreg lifesatisfaction i.workcare4 $A $B $C $D $E if flagsample==1 & agegroup50<=2, i(ID) re vce(robust)
est sto lfst_c
//7 categories
qui xtreg lifesatisfaction i.workcare7 $A $B $C $D $E if flagsample==1 & agegroup50<=2, i(ID) re vce(robust)
est sto lfst_c_int
*margins male, at(agecats=(1 2 3)) atmeans	dydx(provicats) 
margins workcare7#female
marginsplot
//7 cates, gender subgroups
qui xtreg lifesatisfaction i.workcare7 $B $C $D $E if flagsample==1 & agegroup50<=2 & female==0, i(ID) re vce(robust)
est sto lfst_c_intm
qui xtreg lifesatisfaction i.workcare7 $B $C $D $E if flagsample==1 & agegroup50<=2 & female==1, i(ID) re vce(robust)
est sto lfst_c_intw
//7 cates, residency subgroups
qui xtreg lifesatisfaction i.workcare7 $A $C $D $E if flagsample==1 & agegroup50<=2 & ruralh==0, i(ID) re vce(robust)
est sto lfst_c_intu
qui xtreg lifesatisfaction i.workcare7 $A $C $D $E if flagsample==1 & agegroup50<=2 & ruralh==1, i(ID) re vce(robust)
est sto lfst_c_intr
//7 cates, ses subgroups
qui xtreg lifesatisfaction i.workcare7 $A $B $C $E if flagsample==1 & agegroup50<=2 & seshigh==0, i(ID) re vce(robust)
est sto lfst_c_intselow
qui xtreg lifesatisfaction i.workcare7 $A $B $C $E if flagsample==1 & agegroup50<=2 & seshigh==1, i(ID) re vce(robust)
est sto lfst_c_intsehigh
//7 cates, social isolatoin subgroups
qui xtreg lifesatisfaction i.workcare7 $A $B $C $D if flagsample==1 & agegroup50<=2 & soimed==0, i(ID) re vce(robust)
est sto lfst_c_intsilow
qui xtreg lifesatisfaction i.workcare7 $A $B $C $D if flagsample==1 & agegroup50<=2 & soimed==1, i(ID) re vce(robust)
est sto lfst_c_intsihigh
estout lfst_c lfst_c_int lfst_c_intm lfst_c_intw lfst_c_intu lfst_c_intr lfst_c_intselow lfst_c_intsehigh lfst_c_intsilow lfst_c_intsihigh, cells(b(star fmt(3)) se(par fmt(3))) stats(r2 N) legend

**depression
qui xtreg cesd10 i.workcare4 $A $B $C $D $E if flagsample==1 & agegroup50<=2, i(ID) re vce(robust)
est sto dprn_c
//7 cates
qui xtreg cesd10 i.workcare7 $A $B $C $D $E if flagsample==1 & agegroup50<=2, i(ID) re vce(robust)
est sto dprn_c_int
margins workcare7#female
marginsplot
//7 cates, gender subgroups
qui xtreg cesd10 i.workcare7 $B $C $D $E if flagsample==1 & agegroup50<=2 & female==0, i(ID) re vce(robust)
est sto dprn_c_intm
qui xtreg cesd10 i.workcare7 $B $C $D $E if flagsample==1 & agegroup50<=2 & female==1, i(ID) re vce(robust)
est sto dprn_c_intw
//7 cates, residency subgroups
qui xtreg cesd10 i.workcare7 $A $C $D $E if flagsample==1 & agegroup50<=2 & ruralh==0, i(ID) re vce(robust)
est sto dprn_c_intu
qui xtreg cesd10 i.workcare7 $A $C $D $E if flagsample==1 & agegroup50<=2 & ruralh==1, i(ID) re vce(robust)
est sto dprn_c_intr
//7 cates, ses subgroups
qui xtreg cesd10 i.workcare7 $A $B $C $E if flagsample==1 & agegroup50<=2 & seshigh==0, i(ID) re vce(robust)
est sto dprn_c_intselow
qui xtreg cesd10 i.workcare7 $A $B $C $E if flagsample==1 & agegroup50<=2 & seshigh==1, i(ID) re vce(robust)
est sto dprn_c_intsehigh
//7 cates, social isolatoin subgroups
qui xtreg cesd10 i.workcare7 $A $B $C $D if flagsample==1 & agegroup50<=2 & soimed==0, i(ID) re vce(robust)
est sto dprn_c_intsilow
qui xtreg cesd10 i.workcare7 $A $B $C $D if flagsample==1 & agegroup50<=2 & soimed==1, i(ID) re vce(robust)
est sto dprn_c_intsihigh
estout dprn_c dprn_c_int dprn_c_intm dprn_c_intw dprn_c_intu dprn_c_intr dprn_c_intselow dprn_c_intsehigh dprn_c_intsilow dprn_c_intsihigh, cells(b(star fmt(3)) se(par fmt(3))) stats(r2 N) legend


